#include "ijkplayer_linux.h"

#include <assert.h>
#include "ijksdl/linux/ijksdl_linux.h"
#include "../ff_fferror.h"
#include "../ff_ffplay.h"
#include "../ijkplayer_internal.h"
#include "../pipeline/ffpipeline_ffplay.h"

IjkMediaPlayer *ijkmp_linux_create(int(*msg_loop)(void*))
{
    IjkMediaPlayer *mp = ijkmp_create(msg_loop);
    if (!mp)
        goto fail;

    mp->ffplayer->vout = SDL_VoutLinux_Create();
    if (!mp->ffplayer->vout)
        goto fail;

    mp->ffplayer->pipeline = ffpipeline_create_from_ffplay(mp->ffplayer);
    if (!mp->ffplayer->pipeline)
        goto fail;

    return mp;

    fail:
    ijkmp_dec_ref_p(&mp);
    return NULL;
}

void ijkmp_linux_set_display(IjkMediaPlayer *mp, int (*cb)(SDL_Vout *vout, SDL_VoutOverlay *overlay)) {
    if (!mp)
        return;
    SDL_VoutLinux_Display_Set(mp->ffplayer->vout, cb);
}

void ijkmp_linux_set_volume(IjkMediaPlayer *mp, float left, float right)
{
    if (!mp)
        return;

    MPTRACE("ijkmp_android_set_volume(%f, %f)", left, right);
    pthread_mutex_lock(&mp->mutex);

    if (mp && mp->ffplayer && mp->ffplayer->aout) {
        SDL_AoutSetStereoVolume(mp->ffplayer->aout, left, right);
    }

    pthread_mutex_unlock(&mp->mutex);
    MPTRACE("ijkmp_android_set_volume(%f, %f)=void", left, right);
}
